/**
 * The Tapestry GWT client side integration. I took the inspiration from
 * http://www.klauskomenda.com/code/javascript-programming-patterns/#revealing
 * 
 * but I should also check how Tapestry itself does this
 * 
 * @author Alessio Gambi agambi81@gmail.com
 */

// revealing module pattern
var TapestryGWT = function() {
	// Module Data Type:
	// "component" : {
	// "componentParameters" : {
	// "div" : "result",
	// "eventLink" : "/examples/checkbox.checkbox:",
	// "gwtServiceTarget" :
	// "/gwtRemoteService/gwtservice/CheckBoxRemoteService",
	// "eventList" : [
	// "change"
	// ]
	// },
	// "type" : "CheckBox",
	// "componentId" : "checkbox"
	// },
	// "moduleName" : "com.gambi.example.client.GWTUI"

	// This is a private instance
	var moduleSet = new Object();

	var getModule = function(moduleName) {
		// alert("get module " + moduleName);
		return moduleSet[moduleName];
	}

	var registerModule = function(moduleName) {
		// alert("Register Module " + moduleName);
		if (moduleSet[moduleName] == null) {
			moduleSet[moduleName] = new Array();
		}
		// alert("Register Module " + moduleSet.toString());
	}

	var registerComponentInModule = function(moduleName, component) {
		registerModule(moduleName);
		// alert("registerComponentInModule " + moduleName + " - "
		// + component.componentId);
		moduleSet[moduleName].push(component);
		// alert("Components register in " + moduleSet );
		// alert( moduleSet[moduleName].toString());
	}

	return {
		// declare which properties and methods are supposed to be public
		getModule : getModule,
		registerModule : registerModule,
		registerComponentInModule : registerComponentInModule
	}
}();
